<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c"       uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>" />
     <meta http-equiv="content-Type" content="text/html; charset=utf-8" />
    <title>tueye发表文章-tueye发表文章-tueye专业的图片欣赏交流社区</title>
     
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
<link href="<%=path %>/themes/css/index.css" rel="stylesheet" type="text/css" />
<link href="<%=path %>/themes/css/regis.css" rel="stylesheet" type="text/css" /> 

<script type="text/javascript" src="<%=path %>/script/jquery.js"></script>
 
<style type="text/css">
.warning{

}
.code{
  font-size:12px;
}
 
 
</style>
  <script type="text/javascript"> 
$(function(){ 
	     $('form :input').blur(function(){
	         var id = $(this).attr("id");
             $(this).removeClass("warning").parents("td")
			 .find("span.error").remove()
			 .end()
			 .find("span.ok").remove();

		     var $listItem =  $(this).parents("td").find("span:last");
			 //验证email
			if( id == 'Email' ){
			var Email = $(this).attr("value");
				if($(this).attr("value") == null || $(this).attr("value") == ''||(!/.+@.+\.[a-zA-Z]{2,4}$/.test($(this).attr("value")))){
				   
                      var errorMsg = '请输入有效的Email！';
					  $('<span class="error"></span>').css("color","red")
					  $(this).parent().next().text(errorMsg)
					  .appendTo($listItem);
					 
					  $(this).addClass("warning");
				}	else{
				   
                        $.ajax({
            type:"POST",
            url: "<%=request.getContextPath()%>/register.do?action=email", 
            dataType:'action', //接受数据格式 
            data: "Email=" + Email, 
            success: function(data){    
               
                if(data=="true"){  
                 
                      $('#Email').removeClass("warning");
			          var okMsg = '';
                      $('#Email').parent().next().text(okMsg)
                      .appendTo($listItem);
                    
			         
                } else{
                       var errorMsg = 'Email已经有人占用!';
					  $('<span class="error"></span>').css("color","red")
					  $('#Email').parent().next().text(errorMsg)
					  .appendTo($listItem);
					   $(this).addClass("warning");
					  
                }
                }
            })
            }
				}

             //验证昵称
			 if( id == 'byname' ){
			 	var byname = $(this).attr("value");
				if($(this).attr("value") == null || $(this).attr("value") == ''){
                      var errorMsg = '请输入昵称！';
					  $('<span class="error"></span>').css("color","red")
					  $(this).parent().next().text(errorMsg)
					  .appendTo($listItem);
					 
					  $(this).addClass("warning");
				}else{
                       
                        $.ajax({
            type:"POST",
            url: "<%=request.getContextPath()%>/register.do?action=byname", 
            dataType:'action', //接受数据格式 
            data: "byname=" + byname, 
            success: function(data){    
               
                if(data=="true"){  　
                      $('#byname').removeClass("warning");
			          var okMsg = '';
                      $('#byname').parent().next().text(okMsg)
                      .appendTo($listItem);
                    
			         
                } else{
                       var errorMsg = '昵称已经有人占用!';
					  $('<span class="error"></span>').css("color","red")
					  $('#byname').parent().next().text(errorMsg)
					  .appendTo($listItem);
					    $(this).addClass("warning");
					  
                }
                }
            })
                       }
			 
				
			 }
			 //验证密码
			 if( id == 'password1' ){
				if($(this).attr("value") == null || $(this).attr("value") == '' || $(this).attr("value").length<6 || $(this).attr("value").length>12){
                      var errorMsg = '密码必须大于6位小于12位!';
					  $('<span class="error"></span>').css("color","red")
					  $(this).parent().next().text(errorMsg)
					  .appendTo($listItem);
					 
					  $(this).addClass("warning");
				}else{
                       var okMsg = '';
                       $(this).parent().next().text(okMsg)
                       }
			 
				
			 }
			 //验证条款是否打钩
			  if( id == 'check' ){
			 
				if($("#check").attr('checked')==true){
                        var okMsg = '';
                       $(this).parent().next().text(okMsg)
				}else{
                      
                       var errorMsg = '您必须同意注册协议!';
					  $('<span class="error"></span>').css("color","red")
					  alert($(this).parent().html());
					  $(this).parent().next().text(errorMsg)
					  .appendTo($listItem);
					 
					  $(this).addClass("warning");
                       }
			 
				
			 }
			 //验证验证码
			  if( id == 'topic_code' ){
			  var topic_code = $(this).attr("value");
				if($(this).attr("value") == null || $(this).attr("value") == ''){
                      var errorMsg = '验证码不能为空!';
					  $('<span class="error"></span>').css("color","red")
					  $(this).parent().next().text(errorMsg)
					  .appendTo($listItem);
					 
					  $(this).addClass("warning");
				}else{
	         
                       
			  var okMsg = '';
                       $(this).parent().next().text(okMsg)
				
			    }
           }
	 })
	

         
		 //提交，最终验证。
		$("#tijiao").bind("click", function(){
       
			$(":input").trigger('blur');
		
			var numWarning = $('.warning',$('form')).length;
			
            if(numWarning){
			    var errorFieldList = [];
                $(".warning").each(function(){
					errorFieldList.push( $(this).prev("span").text() );
				})
				
				return false;
			}  
			var Email = $('#Email').val();　
			var byname =  $('#byname').val();
			var password =  $('#password1').val();
			var nowHome =  $('#nowHome').val();
			var topic_code =  $('#topic_code').val();
			var sendData= "Email="+encodeURIComponent(Email)+"&byname="+encodeURIComponent(byname)+"&password1="+password+"&nowHome="+encodeURIComponent(nowHome)+"&topic_code="+topic_code;
			$.ajax({
            type:"POST",
            url: "<%=request.getContextPath()%>/register.do?action=save", 
            dataType:'html', //接受数据格式
            async: false,
            data: sendData,
            beforeSend:loaddd(),
            success: function(data){   
                  if(data=='true'){ 
                    $("#loadtip2").show(); 
                    window.setTimeout("window.location='<%=path %>/pages/topics/usermanager/userlogin.jsp'", 300) 
                  }else{
                    //显示在验证码后面
                   $('#topic_code').parent().next().html("<font color='red'>验证码输入错误!</font>");
                   refrash(); 
                  }  
                },
           error:function(data){
             alert(data);
           },
           complete:complatedd()
           　    
            }) 
      });
	  
		
		 
		 
	})
	  function complatedd(){
	    $('#loadtip').hide();
	  }
      function loaddd(){
        $('#loadtip').show();
      }
		function refrash(){
		$('#imgId')[0].src+='?'+Math.floor(Math.random()*10);
		}
  </script>
</head>

<body>
 <%@ include file="../../../../common/header.jsp" %>
<div id="container">
<div id="mainbody">
   <h1> 注册成为TuEye会员</h1>
	<div id="tip"><a href="<%=path %>/pages/topics/usermanager/userlogin.jsp">已是会员，请登陆</a></div>
	<form method="post" action="" name="register" id="register" >
	<table>
	 <tr><td colspan="2"><div style="display:none;" id="loadtip"><img src="<%=path%>/themes/images/spinner40.gif"/></div>
	 <div style="display:none;" id="loadtip2"><img src="<%=path%>/themes/images/success.gif"　width="30px" height="20px"/><font color="red">注册成功,稍等转向登录界面</font></div> 
	 </td></tr>
	 <tr><td width="20%"  align="right">
	  Email:
	 </td><td align="left" width="30%"><input type="text" name="Email" id="Email"/></td><td class="regtip" align="right"></td></tr>
	 <tr><td  width="20%" align="right">
	  昵称:
	 </td><td align="left"><input type="text"  name="byname" id="byname" /></td><td class="regtip"></td></tr>
	 <tr><td  width="20%" align="right">
	  设置密码:
	 </td><td align="left"><input type="password"  name="password" id="password1" value=""/></td><td class="regtip"></td></tr>
	 <tr><td  width="20%" align="right">
	 常居地:
	 </td><td align="left"><select name="nowHome" id="nowHome"><option value="北京">B北京</option>
	 <option value="长春">C长春</option>
	<option value="长沙">C长沙</option>
	<option value="成都">C成都</option>
	<option value="重庆">C重庆</option>
	<option value="大连">D大连</option>
	<option value="东莞">D东莞</option>
	<option value="佛山">F佛山</option>
	<option value="福州">F福州</option>
	<option value="广州">G广州</option>
	<option value="贵阳">G贵阳</option>
	<option value="哈尔滨">H哈尔滨</option>
	<option value="海南">H海南</option>
	<option value="杭州">H杭州</option>
	<option value="合肥">H合肥</option>
	<option value="呼和浩特">H呼和浩特</option>
	<option value="济南">J济南</option>
	<option value="昆明">K昆明</option>
	<option value="兰州">L兰州</option>
	<option value="南昌">N南昌</option>
	<option value="南京">N南京</option>
	<option value="南宁">N南宁</option>
	<option value="宁波">N宁波</option>
	<option value="青岛">Q青岛</option>
	<option value="上海">S上海</option>
	<option value="沈阳">S沈阳</option>
	<option value="深圳">S深圳</option>
	<option value="石家庄">S石家庄</option>
	<option value="苏州">S苏州</option>
	<option value="太原">T太原</option>
	<option value="天津">T天津</option>
	<option value="武汉">W武汉</option>
	<option value="乌鲁木齐">W乌鲁木齐</option>
	<option value="无锡">W无锡</option>
	<option value="厦门">X厦门</option>
	<option value="西安">X西安</option>
	<option value="西宁">X西宁</option>
	<option value="扬州">Y扬州</option>
	<option value="郑州">Z郑州</option>
	<option value="珠海">Z珠海</option>
	<option value="其它城市">M其它城市</option>
	</select>
	 </td><td class="regtip"></td></tr>
	 <tr><td  width="20%" align="right">
	  验证码:
	 </td><td align="left"><input type="text"   name="topic_code" id="topic_code"  /></td><td class="regtip"></td></tr>
	 <tr> <td colspan="3" align="center">
	 <img  id ='imgId' src="servlet/createimage" onclick="this.src+='?'+Math.floor(Math.random()*10);" alt="点击刷新" />点图<a href ="javascript:refrash()">刷新</a></td><td class="regtip"></td></tr>
	 <tr> <td colspan="3" align="center"><input type="checkbox" id="check" checked="checked" /> 我已经阅读并同意我已经阅读并同意<a href="<%=path %>/pages/topics/service/regdesc.jsp" target="_blank">TuEye网注册协议 </a> </td><td class="regtip"></td></tr>
	 <tr> <td colspan="3" align="center"><input type="button"  id="tijiao" value="提交注册" /></td></tr>
	</table>
	</form>
 </div>
 </div>
<%@ include file="../../../../common/footer.jsp" %>
</body>
</html>

